<?php

	include("common.php");
	
	if(!empty($_POST)){
		mysql_query("INSERT INTO `197_sidebar` ( `title`, `content`, `position` ) VALUES ( '" . $_POST['title'] . "', '" . $_POST['content'] . "', " . $_POST['position'] . " )");
		include("header.php");
?>
<?php if(!AJAX){ ?><h1>新增側欄項目</h1><?php } ?>
<p>新增成功<?php if(!AJAX){ ?>，請<a href="sidebarFind.php">按此</a>返回<?php } ?>。</p>
<?php

		include("sidebar.php");
		include("footer.php");
		
		exit;

	}
	
?>
<?php include("header.php"); ?>
<h1>新增側欄項目</h1>
<div id="add-result-dialog">
</div>
<script type="text/javascript" defer="defer">
	$("#add-result-dialog").dialog({
		width: 300,
		height: 210,
		autoOpen: false,
		title: "新增側欄項目",
		modal: true,
		draggable: false,
		resizable: false
	});
	function addSidebar(){
		$("#add-result-dialog").dialog("option", "buttons", { "關閉": function(){ location.replace("sidebarFind.php"); } });
		$("#add-result-dialog").html("<img src='../images/ajax-loader.gif' />");
		$("#add-result-dialog").dialog("open");
		$.post("sidebarAdd.php?ajax=true", { title: $("#title").val(), content: $("#content").val(), position: $("#position").val() }, function(r){ $("#add-result-dialog").html(r) });
	}
</script>
<form action="sidebarAdd.php" id="sidebar-add-form" onsubmit="addSidebar(); return false;" method="POST">
	<p><label>標題：<input type="text" name="title" id="title" /></label></p>
	<textarea name="content" id="content" cols="50" rows="20"></textarea>
	<p><label>位置：<select name="position" id="position"><option value="0" selected="selected">左</option><option value="1">右</option></select></label></p>
	<p><input type="submit" value="新增" />｜<a href="sidebarFind.php">返回</a></p>
</form>
<?php include("sidebar.php"); ?>
<?php include("footer.php"); ?>